Options
All
  • Public
  • Public/Protected
  • All
Menu

onprint-sdk-light

Onprint Javascript SDK Light

This SDK has for objective to let you explore ONprint image recognition tools faster by wraping ONprint API request and provides simple methods to access it

Instalation

npm install -S onprint-sdk-light

Usage

There is two way to use this SDK:

SDK Class Object

This object contain all the methods to request an Enriched Image (by Id or File), and Send Click action to feed the reporting

Initialize SDK

To initialize the SDK you need to provide informations used by our reporting service:

  • Device Header
  • Application Header
  • Api Key
import {SdkLight} from 'onprint-sdk-light';

const applicationHeader = {
    name: 'Your Application App Name',
    version: '1.0.0',
    id: 'Random Id'
};

const deviceHeader = {
    name: 'A Device Name',
    version: '8.0.0',
    versionName: 'Oreo'
};

const sdk = new SdkLight(YOUR_API_KEY, applicationHeader, deviceHeader);

By default the lang is set to 'fr-FR' but you can change it with:

sdk.setLang('en-EN')

more precision with the Lang features here: ONprint API

Scan Enriched Image

The ONprint API provides you 2 ways to request Enriched Images

  • With Image Id

      try {
          const enrichedImage = await sdk.getEnrichedImageById('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
      } catch (err) {
          console.log(err);
      }
  • With Image File

      try {
          const imgBuffer = fs.readFileSync('image.jpeg');
          const enrichedImage = await sdk.getEnrichedImageByImage(imageBuffer);
      } catch (err) {
          console.log(err);
      }

Scan Picture

The ONprint API provides you 2 ways to request Pictures

  • With Image Id

      try {
          const picture = await sdk.getPictureByImage('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
      } catch (err) {
          console.log(err);
      }
  • With Image File

      try {
          const imgBuffer = fs.readFileSync('picture.jpeg');
          const pictures = await sdk.getPictureByImage(imageBuffer);
      } catch (err) {
          console.log(err);
      }

As you can see, the SDK methodes return Promise, if an error occure the SDK will throw an Error to catch.

Click on Action

This features is really important to get feedback of your user and have data on which content is most used. To work the Click methode need to get 2 arguments:

- ActionId find in the EnrichedImages responses Actions attribute
- SessionId Automaticly set to the last valid Enriched Image request

The methode return true in case of success

try {
    const enrichedImage = await sdk.getEnrichedImageById('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
    sdk.clickOnAction(enrichedImage.Actions[0].Id);
} catch (err) {
    console.log(err);
}

API Functions

If you prefer not use the SDK Class we provide you, it's possible to use directly the Onprint API call and have more controle with the functions return and behavior.

Enriched Image

Picture

Click Stream

Test

To run test simply launch the command with your API KEY

API_KEY=your_api_key npm run test

Support

You can contact me for any issue at bmartins@ltutech.com

License

© LTU Tech 2018 All Rights Reserved

Generated using TypeDoc